package com.nativetalk.service.three.setmeal.Search;

import com.nativetalk.base.RetInfo;
import com.nativetalk.bean.course.TwoTsNtCourseInfoDetail;
import com.nativetalk.bean.member.setmeal.TdNtMembSetmealDetail;
import com.nativetalk.common.ValidationMessages;
import com.nativetalk.common.util.MemcachedKey;
import com.nativetalk.common.util.MemcachedUtils;
import com.nativetalk.dao.TdNtMembSetmealDao;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by lizhun on 16/6/15.
 */
@Service
public class ThreeSetmealSearchServiceImpl implements  ThreeSetmealSearchService{
    private static Logger logger = Logger.getLogger(ThreeSetmealSearchServiceImpl.class);
    @Resource
    private TdNtMembSetmealDao tdNtMembSetmealDao;
    @Override
    public RetInfo findTdNtMembSetmealDetail(Map<String,Object> map) {
        String logInfo = this.getClass().getName() + ":findTdNtMembSetmealDetail:";
        // 类路径+方法名
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            Map<String , TwoTsNtCourseInfoDetail> tsNtCourseInfoDetailMap = (Map<String , TwoTsNtCourseInfoDetail> ) MemcachedUtils.get(MemcachedKey.tsNtCourseInfoDetailMapTwo);
            TwoTsNtCourseInfoDetail  tsNtCourseInfoDetail = tsNtCourseInfoDetailMap.get(map.get("cou_id").toString());
            map.put("cou_id",tsNtCourseInfoDetail.getCate_id());
            TdNtMembSetmealDetail tdNtMembSetmealDetail = tdNtMembSetmealDao.findTdNtMembSetmealDetail(map);
            Map<String, Object> result = new HashMap<>();
            if (tdNtMembSetmealDetail != null) {

                result.put("is_buy", 0);
                result.put("surplus_time", tdNtMembSetmealDetail.getSurplus_time());
                retInfo.setMark(ValidationMessages.getValue("MARKYES"));
                retInfo.setTip("成功");
                retInfo.setObj(result);
            } else {
                retInfo.setMark(ValidationMessages.getValue("MARKNO"));
                retInfo.setTip("暂无套餐");
                result.put("is_buy", 1);
                result.put("surplus_time",0);
            }

        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(),e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
}
